import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * 1、自定义异常，一定要继承Exception或者....
 * 2、
 *
 * User: GaoBo
 * Date: 2021-05-30
 * Time: 7:56
 */


//MyException2 默认受查异常  编译时异常
class MyException2 extends Exception{

}

//MyException 默认非受查异常 运行时异常
class MyException extends RuntimeException{
    public MyException(String msg) {
        super(msg);
    }
}
class MyException3 extends IOException {
    public MyException3(String msg) {
        super(msg);
    }
}


class UserException extends Exception {
    public UserException(String message) {
        super(message);
    }
}

class PasswordException extends Exception {
    public PasswordException(String message) {
        super(message);
    }
}



public class TestDemo {
    private static String userName = "admin";
    private static String password = "123456";

    public static void login(String userName, String password) throws UserException,
            PasswordException {
        if (!TestDemo.userName.equals(userName)) {
            throw new UserException("用户名错误");
        }
        if (!TestDemo.password.equals(password)) {
            throw new PasswordException("密码错误");
        }
        System.out.println("登陆成功");
    }

    public static void main(String[] args) {
        try {
            login("admin", "123456");
        } catch (UserException userError) {
            userError.printStackTrace();
        } catch (PasswordException passwordError) {
            passwordError.printStackTrace();
        }
    }

    public static void main3(String[] args) {
        int a = 10;
        if(a == 10) {
            //throw new MyException();
            throw new MyException("fdfadfadfa");
        }
    }
    public static double div(int a,int b) throws ArithmeticException,NullPointerException {
        if(b == 0) {
            throw new ArithmeticException("b == 0");
        }
        if(a == 1) {
            throw new NullPointerException();
        }
        return a/b;
    }
    public static void main2(String[] args) {
        System.out.println(div(10,0));
        /*
        try {
            System.out.println(div(10,0));
        }catch (ArithmeticException | NullPointerException e) {
            e.printStackTrace();
        }*/

        System.out.println("fdsfafads");
    }

    /*public void getCustomerInfo() {
        try {
            // do something that may cause an Exception
            int a = 1;
            if(a == 1) {
                throw new IOException();
            }
        } catch (java.lang.Exception ex) {

            System.out.print("Exception!");

        }  catch (java.io.IOException ex) {

            System.out.print("IOException!");

        }catch (java.io.FileNotFoundException ex) {
            System.out.print("FileNotFoundException!");
        }

    }*/




    /*public void getCustomerInfo1() {
        try {
            // do something that may cause an Exception
            int a = 1;
            if(a == 1) {
                throw new FileNotFoundException();
            }
        } catch (java.io.FileNotFoundException ex) {

            System.out.print("FileNotFoundException!");

        } catch (java.io.IOException ex) {

            System.out.print("IOException!");

        } catch (java.lang.Exception ex) {

            System.out.print("Exception!");

        }*/

    //}
}
